package com.project.controller;

import com.project.bean.StudentBean;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ThmeleafController {
    @Autowired
    private IStudentService service;

    @RequestMapping("/")
    public String index(HttpServletRequest req){
        req.setAttribute("name","张三");
        req.setAttribute("age",20);
        req.setAttribute("list",service.findAll());
        return "/leaf/index.html";
    }

    @RequestMapping("/del")
    public String del(int id){
        service.del(id);
        return "redirect:/";
    }

    @RequestMapping("/add")
    public String add(StudentBean student){
        service.add(student);
        return "redirect:/";
    }
}
